package com.deer.wms.inventory.web;

import com.deer.wms.inventory.model.InCellTask;
import com.deer.wms.inventory.model.InCellTaskCriteria;
import com.deer.wms.inventory.service.InCellTaskService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.deer.wms.project.root.core.result.Result;
import com.deer.wms.project.root.core.result.ResultGenerator;

import java.util.List;

/**
* Created by ll on 2020/03/05.
*/
@RestController
@RequestMapping("/in/cell/tasks")
public class InCellTaskController {

    @Autowired
    private InCellTaskService inCellTaskService;

    @PostMapping
    public Result add(@RequestBody InCellTask inCellTask) {
        inCellTaskService.save(inCellTask);
        return ResultGenerator.genSuccessResult();
    }

    @DeleteMapping("/{id}")
    public Result delete(@PathVariable Integer id) {
        inCellTaskService.removeById(id);
        return ResultGenerator.genSuccessResult();
    }

    @PutMapping
    public Result update(@RequestBody InCellTask inCellTask) {
        inCellTaskService.updateById(inCellTask);
        return ResultGenerator.genSuccessResult();
    }

    @GetMapping("/{id}")
    public Result detail(@PathVariable Integer id) {
        InCellTask inCellTask = inCellTaskService.getById(id);
        return ResultGenerator.genSuccessResult(inCellTask);
    }

    @GetMapping
    public Result list(InCellTaskCriteria criteria) {
        PageHelper.startPage(criteria.getPageNum(), criteria.getPageSize());
        List<InCellTask> list = inCellTaskService.list();
        PageInfo pageInfo = new PageInfo(list);
        return ResultGenerator.genSuccessResult(pageInfo);
    }
}
